package cn.lingyangwl.agile.infra.weixin.mp.controller;

import cn.lingyangwl.agile.infra.weixin.mp.model.entity.MpTag;
import cn.lingyangwl.agile.infra.weixin.mp.model.rqrs.MpTagListReq;
import cn.lingyangwl.agile.infra.weixin.mp.model.rqrs.MpTagPageReq;
import cn.lingyangwl.agile.infra.weixin.mp.model.rqrs.MpTagReq;
import cn.lingyangwl.agile.infra.weixin.mp.service.MpTagService;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.framework.core.response.Resp;
import cn.lingyangwl.framework.validation.group.UpdateGroup;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 公众号标签
 * 
 * @author shenguangyang
 */
@Api(tags = "公众号标签")
@RestController
@RequestMapping("/mpTag")
public class MpTagController {
    @Resource
    private MpTagService mpTagService;
  
    /**
     * 分页 公众号标签
     */
    @RamResource(action = "weixin:mpTag:query", type = ActionType.READ, name = "查询公众号标签")
    @GetMapping("/pageMpTag")
    public Resp<IPage<MpTag>> pageMpTag(@Validated MpTagPageReq req) {
        return Resp.ok(mpTagService.pageMpTag(req));
    }

    /**
     * 查询 公众号标签
     */
    @RamResource(action = "weixin:mpTag:query", type = ActionType.READ, name = "查询公众号标签")
    @GetMapping("/listMpTag")
    public Resp<List<MpTag>> listMpTag(@Validated MpTagListReq query) {
        return Resp.ok(mpTagService.listMpTag(query));
    }
  
    /**
     * 通过id查找 公众号标签
     */
    @GetMapping("/getMpTag")
    @RamResource(action = "weixin:mpTag:query", type = ActionType.READ, name = "查询公众号标签")
    public Resp<MpTag> getMpTagById(@RequestParam(value = "id") Long id) {
        return Resp.ok(mpTagService.getMpTagById(id));
    }
  
    /**
     * 保存 公众号标签
     */
    @PostMapping("/saveMpTag")
    @RamResource(action = "weixin:mpTag:save", type = ActionType.WRITE, name = "保存公众号标签")
    public Resp<?> saveMpTag(@Validated @RequestBody MpTagReq rq) {
        return Resp.ok(mpTagService.saveMpTag(rq));
    }
  
    /**
     * 更新 公众号标签
     */
    @RamResource(action = "weixin:mpTag:update", type = ActionType.WRITE, name = "更新公众号标签")
    @PostMapping("/updateMpTag")
    public Resp<?> updateMpTagById(@Validated(UpdateGroup.class) @RequestBody MpTagReq rq) {
        return Resp.ok(mpTagService.updateMpTagById(rq));
    }
  
    /**
     * 删除 公众号标签
     */
    @RamResource(action = "weixin:mpTag:delete", type = ActionType.WRITE, name = "删除公众号标签")
    @DeleteMapping("/deleteMpTag")
    public Resp<?> delete(@RequestParam(value = "id") Long id) {
        return Resp.ok(mpTagService.deleteMpTagById(id));
    }

    /**
     * 删除 公众号标签
     */
    @RamResource(action = "weixin:mpTag:syncMpTag", type = ActionType.WRITE, name = "同步公众号标签")
    @PostMapping("/syncMpTag")
    public Resp<?> syncMpTag() {
        mpTagService.syncMpTag();
        return Resp.ok();
    }
}
